
import iaa = module("main/org/sdmx/model/v2/base/IdentifiableArtefactAdapter");
import itm = module("main/org/sdmx/model/v2/base/item/Item");
import rep = module("main/org/sdmx/model/v2/base/structure/Representation");
import dt = module("main/org/sdmx/model/v2/base/type/DataType");
import cr = module("main/org/sdmx/model/v2/base/type/ConceptRole");
import cpt = module("main/org/sdmx/model/v2/structure/concept/Concept");

/**
	* Defines qualitative and quantitative data and metadata items that belong 
	* to a ComponentList and hence a Structure.
	* 
	* @author Xavier Sosnovsky, Anthony Morel
	* 
	* @see ComponentList
	*/
export class Component extends iaa.IdentifiableArtefactAdapter {
    
    /*==============================Fields================================*/
    
    private _conceptIdentity: cpt.Concept;
		
	private _conceptRole:string;
		
	private _localType:string;
		
	private _localRepresentation:rep.Representation;
		
	/*===========================Constructor==============================*/
		
	/**
		* Constructs a component.
		*  
		* @param identifier The attribute id
		* @param conceptIdentity The concept representing a component
		*/
	constructor(identifier:string, concept:cpt.Concept) {
		super(identifier);
		this.setConceptIdentity(concept);
	}
		
	/*============================Accessors===============================*/
		
	/**
		* @private 
		*/
	public setConceptIdentity(concept:cpt.Concept) {
		if (null == concept) {
			throw new Error("The concept identity cannot be null");
		}
		this._conceptIdentity = concept;
	}
		
	/**
		* The concept from which the component takes its semantic. 
		*/
	public getConceptIdentity():cpt.Concept {
		return this._conceptIdentity;
	}
		
	/**
		* @private 
		*/
	public setConceptRole(conceptRole:string) {
		if (!cr.ConceptRole.contains(conceptRole)) {
			throw new Error(conceptRole + 
				" is not a valid concept role");
		}
		this._conceptRole = conceptRole;
	}
		
	/**
		* The role played by the component in a structure. For example,
		* the concept "FREQ" plays the role of the frequency dimension in a
		* certain data structure definition. 
		*/
	public getConceptRole():string {
		return this._conceptRole;
	}
		
	/**
		* @private 
		*/
	public setLocalType(localType:string) {
		if (!dt.DataType.contains(localType)) {
			throw new Error(localType + 
				" is not a valid SDMX data type");
		}
		this._localType = localType;
	}
		
	/**
		* Type taken by a component in a certain structure. If supplied, it
		* overrides any type specified for the item which contains its concept
		* identity. 
		*/
	public getLocalType():string {
		return this._localType;
	}
		
	/**
		* @private 
		*/
	public setLocalRepresentation(localRepresentation:rep.Representation) {
		this._localRepresentation = localRepresentation;
	}
		
	/**
		* Default representation of the concept (for instance a CodeList).
		*/
	public getLocalRepresentation():rep.Representation {
		return this._localRepresentation;
	}
}